from selenium.webdriver.common.by import By
from ..testLogin.LoginOperation import LoginOperation
from ..PublicOperations import PublicOperations
from selenium.webdriver.common.by import By
import time


class BuyOperation:
    # 零钱
    def buy_small_change(self,driver,username,pwd,buyPwd):

        log = LoginOperation()
        log.login(driver,username,pwd)
        PublicOperations.Operate(driver,2,1)
        self.common_operation(driver,buyPwd)
        time.sleep(1)
    # 期限
    def buy_fund(self,driver,username,pwd,buyPwd):

        log = LoginOperation()
        log.login(driver,username,pwd)
        PublicOperations.Operate(driver,2,2)
        self.common_operation(driver,buyPwd)
        time.sleep(1)

    # 基金
    def buy_share_certificate(self,driver,username,pwd,buyPwd):
        log = LoginOperation()
        log.login(driver, username, pwd)
        PublicOperations.Operate(driver, 2, 3)
        self.common_operation(driver, buyPwd)
        time.sleep(1)


    def common_operation(self,driver,buyPwd):
        driver.find_element(By.XPATH, '//div[@class="table-responsive"]/table/tbody/tr[1]/td[last()]/button').click()
        # 选择投资
        time.sleep(2)
        driver.find_element(By.XPATH, '//div[@class="layui-layer-content"]/input[@id="password"]').send_keys(buyPwd)
        driver.find_element(By.XPATH, "//div[@id='layui-layer1']/div[last()]/a[1]").click()
        time.sleep(2)


    def get_buy_result(self,driver):

        return driver.find_element(By.XPATH,'//div[@class="jconfirm-content"]/div').text

